package cz.muni.fi.pa165.sme.dao.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import cz.muni.fi.pa165.sme.dao.api.PersistentEntity;

/**
 * Entity representing burned calories record.
 *
 * @author Amruz
 */
@Entity
@Table(name = "burned_calories")

@NamedQueries({
		@NamedQuery(name = BurnedCalories.SELECT_BY_SPORT_ACTIVITY,
				query = "SELECT bc from BurnedCalories bc WHERE bc.sportActivity.id = :sportActivityId"),
		@NamedQuery(name = BurnedCalories.SELECT_ALL, query = "select bc from BurnedCalories bc"),
		@NamedQuery(name = BurnedCalories.SELECT_HIGHER_THAN, query = "select bc from BurnedCalories bc where bc.calories > :cals")
})

public class BurnedCalories implements PersistentEntity {

	public static final String SELECT_BY_SPORT_ACTIVITY = "bc.selectBySportActivity";
	public static final String SELECT_ALL = "bc.selectAll";
	public static final String SELECT_HIGHER_THAN = "bc.selectHigherThan";

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	@JoinColumn(name = "id_sport_activity")
	@ManyToOne(targetEntity = SportActivity.class)
	private SportActivity sportActivity;

	@Column(name = "calories")
	private Long calories;
	@Column(name = "weight")
	private Float weight;
	@Column(name = "speed")
	private Float speed;

	public Long getId() {
		return id;
	}

	public void setId(final Long id) {
		this.id = id;
	}

	public SportActivity getSportActivity() {
		return sportActivity;
	}

	public void setSportActivity(final SportActivity sportActivity) {
		this.sportActivity = sportActivity;
	}

	public Long getCalories() {
		return calories;
	}

	public void setCalories(final Long calories) {
		this.calories = calories;
	}

	public Float getWeight() {
		return weight;
	}

	public void setWeight(final Float weight) {
		this.weight = weight;
	}

	public Float getSpeed() {
		return speed;
	}

	public void setSpeed(final Float speed) {
		this.speed = speed;
	}

	@Override
	public boolean equals(final Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		final BurnedCalories that = (BurnedCalories) o;


		return !(id == null || (!id.equals(that.id)));
	}

	@Override
	public int hashCode() {
		return id != null ? id.hashCode() : 0;
	}

	@Override
	public String toString() {
		return "BurnedCalories{" +
				"id=" + id +
				", sportActivity=" + sportActivity +
				", calories=" + calories +
				", weight=" + weight +
				", speed=" + speed +
				'}';
	}
}
